﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    
	  xmlns:EdiAvalonEdit="clr-namespace:ICSharpCode.AvalonEdit.Edi;assembly=ICSharpCode.AvalonEdit"
	  xmlns:AvalonEdit="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit"
    xmlns:editing="clr-namespace:ICSharpCode.AvalonEdit.Editing;assembly=ICSharpCode.AvalonEdit"
    xmlns:rendering="clr-namespace:ICSharpCode.AvalonEdit.Rendering;assembly=ICSharpCode.AvalonEdit"

    xmlns:AEComplete="clr-namespace:ICSharpCode.AvalonEdit.CodeCompletion;assembly=ICSharpCode.AvalonEdit"
    
    xmlns:pinlvw="clr-namespace:SimpleControls.MRU.View;assembly=SimpleControls"
    xmlns:hyperl="clr-namespace:SimpleControls.Hyperlink;assembly=SimpleControls"
  
    xmlns:unit="clr-namespace:UnitComboLib;assembly=UnitComboLib"
    >
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Themes;component/MetroLight/Brushes.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <Style TargetType="{x:Type EdiAvalonEdit:EdiTextEditor}">
    <Setter Property="Foreground"            Value="{DynamicResource EditorForeground}" />
    <Setter Property="Background"            Value="{DynamicResource EditorBackground}" />
    <Setter Property="LineNumbersForeground" Value="{DynamicResource EditorLineNumbersForeground}" />
    <Setter Property="FlowDirection" Value="LeftToRight"/><!-- AvalonEdit does not support RTL, so ensure we use LTR by default -->
    <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type EdiAvalonEdit:EdiTextEditor}">
          <ControlTemplate.Resources>
            <Style TargetType="{x:Type rendering:TextView}">
              <Setter Property="NonPrintableCharacterBrush" Value="{DynamicResource NonPrintableCharacterBrush}" />
              <Setter Property="LinkTextForegroundBrush"    Value="{DynamicResource LinkTextForegroundBrush}" /> <!-- Style hyperlink displayed within text in text editor -->
              <Setter Property="LinkTextBackgroundBrush"    Value="{DynamicResource LinkTextBackgroundBrush}" />
            </Style>

            <Style TargetType="{x:Type editing:TextArea}">
              <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
              <Setter Property="SelectionBrush" Value="{DynamicResource EditorSelectionBrush}" />
              <Setter Property="FlowDirection" Value="LeftToRight" />
              <Setter Property="SelectionBorder">
                <Setter.Value>
                  <Pen Brush="{DynamicResource EditorSelectionBorder}" Thickness="1"/>
                </Setter.Value>
              </Setter>
              <Setter Property="SelectionForeground" Value="{x:Null}"/><!-- Set to null to let highlighting shine through selection -->
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type editing:TextArea}">
                    <DockPanel Focusable="False">
                      <ItemsControl DockPanel.Dock="Left"
						              Focusable="False"
						              ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=LeftMargins}">
                        <ItemsControl.ItemsPanel>
                          <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                          </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                      </ItemsControl>
                      <ContentPresenter Panel.ZIndex="-1"
							                          Focusable="False"
							                          Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextView}"/>
                    </DockPanel>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>

            <Style TargetType="{x:Type editing:LineNumberMargin}">
              <Setter Property="Control.Cursor" Value="/ICSharpCode.AvalonEdit;component/themes/RightArrow.cur"/>
              <Setter Property="Margin" Value="9,0,15,0" />
            </Style>

            <Style TargetType="{x:Type ListBoxItem}" x:Key="CompletionListBoxItem">
              <Setter Property="Background"      Value="#FF000000" />
              <!-- Background of each item -->
              <Setter Property="BorderThickness" Value="0" />
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border Name="Bd"
					                  Background="{TemplateBinding Background}"
					                  BorderBrush="{TemplateBinding BorderBrush}"
					                  BorderThickness="{TemplateBinding BorderThickness}"
					                  Padding="{TemplateBinding Padding}"
					                  SnapsToDevicePixels="true">

                      <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
							                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
							                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                    <!-- Simplified triggers: don't want a gray selection background when the ListBox doesn't have focus -->
                    <ControlTemplate.Triggers>
                      <Trigger Property="IsSelected" Value="true">
                        <Setter Property="Background" Value="#FF393939"/>
                        <Setter Property="BorderBrush" TargetName="Bd" Value="#7FFFFFFF" />
                      </Trigger>
                    </ControlTemplate.Triggers>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>

            <Style TargetType="{x:Type AEComplete:CompletionList}">
              <!-- Setter Property="BorderThickness" Value="5" / -->
              <!-- Setter Property="BorderBrush" Value="Green" / -->
              <!-- Setter Property="Background" Value="Red" / -->
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type AEComplete:CompletionList}">
                    <AEComplete:CompletionListBox x:Name="PART_ListBox" ItemContainerStyle="{DynamicResource CompletionListBoxItem}">
                      <ItemsControl.ItemTemplate>
                        <DataTemplate>
                          <StackPanel Orientation="Horizontal">
                            <ContentControl Content="{Binding Content}" />
                          </StackPanel>
                        </DataTemplate>
                      </ItemsControl.ItemTemplate>
                    </AEComplete:CompletionListBox>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>

            <!-- Remove window frame from pop-up completion window -->
            <Style TargetType="{x:Type AEComplete:CompletionWindowBase}">
              <Setter Property="MaxHeight" Value="600" />
              <Setter Property="MaxWidth" Value="215" />
              <Setter Property="Background" Value="#00000000" />
              <Setter Property="BorderThickness" Value="0" />
              <Setter Property="BorderBrush" Value="{x:Null}" />
              <Setter Property="WindowStyle" Value="None" />
              <Setter Property="AllowsTransparency" Value="True" />
            </Style>

          </ControlTemplate.Resources>
          <Border Background="{TemplateBinding Background}"
							      BorderBrush="{TemplateBinding BorderBrush}"
							      BorderThickness="{TemplateBinding BorderThickness}">

            <ScrollViewer Focusable="False"
						            Name="PART_ScrollViewer"
						            CanContentScroll="True"
						            VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}"
						            HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}"
						            Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextArea}"
						            VerticalContentAlignment="Top"
						            HorizontalContentAlignment="Left"
						            Background="{TemplateBinding Background}"
						            Padding="{TemplateBinding Padding}"
						            BorderBrush="{TemplateBinding BorderBrush}"
					              BorderThickness="{TemplateBinding BorderThickness}">
              <ScrollViewer.Template>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                  <Border BorderBrush="{TemplateBinding BorderBrush}"
					              BorderThickness="{TemplateBinding BorderThickness}"
                        HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalAlignment}">
                    <Grid Background="{TemplateBinding Background}"
                        HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalAlignment}">
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                      </Grid.ColumnDefinitions>
                      <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                      </Grid.RowDefinitions>

                      <!-- Display TextEditor content in upper left corner -->
                      <ScrollContentPresenter Grid.Column="0" Grid.Row="0"
                                              KeyboardNavigation.DirectionalNavigation="Local"
                                              CanContentScroll="True"
                                              CanHorizontallyScroll="True"
                                              CanVerticallyScroll="True"
						                                  Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type EdiAvalonEdit:EdiTextEditor}}, Path=TextArea}"
                                            />

                      <!-- Display Vertical Scrollbar to the right -->
                      <ScrollBar Name="PART_VerticalScrollBar"
                                 Grid.Column="1"
                                 Value="{TemplateBinding VerticalOffset}"
                                 Maximum="{TemplateBinding ScrollableHeight}"
                                 ViewportSize="{TemplateBinding ViewportHeight}"
                                 Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>

                      <!-- Display mini-toolbar and Horizontal scrollbar at the bottom of the view -->
                      <!-- Using DialogBackgroundBrush since Editor can use a WPF Theme independent background color -->
                      <!-- TODO XXX Background="{DynamicResource DialogBackgroundBrush}" -->
                      <Grid Grid.Column="0" Grid.Row="1">
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto" />
                          <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <unit:UnitCombobox DataContext="{Binding SizeUnitLabel}"
                                           FontSize="12"
                                           ItemsSource="{Binding SelectedItem.DefaultValues}"
                                           ToolTip="{Binding ValueTip}"
                                           HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                           Grid.Column="0"
                                           Margin="3,0"
                                           Padding="0"
                                           BorderThickness="1"
                                           BorderBrush="Transparent"
                                           IsEditable="True">
                          <unit:UnitCombobox.Text>
                            <Binding Path="StringValue" Mode="TwoWay" ValidatesOnDataErrors="True"/>
                          </unit:UnitCombobox.Text>
                        </unit:UnitCombobox>

                        <ScrollBar Name="PART_HorizontalScrollBar"
                                 Orientation="Horizontal"
                                 Grid.Column="1"
                                 Value="{TemplateBinding HorizontalOffset}"
                                 Maximum="{TemplateBinding ScrollableWidth}"
                                 ViewportSize="{TemplateBinding ViewportWidth}"
                                 Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                      </Grid>
                      <!-- Using DialogBackgroundBrush since Editor can use a WPF Theme independent background color -->
                      <!-- TODO XXX  Background="{DynamicResource DialogBackgroundBrush}" -->
                      <DockPanel Grid.Column="1" Grid.Row="1" LastChildFill="false">
                        <!-- Rectangle Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Width="1" Fill="White" DockPanel.Dock="Left" />
                      <Rectangle Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Height="1" Fill="White" DockPanel.Dock="Top" / -->
                      </DockPanel>
                    </Grid>
                  </Border>
                </ControlTemplate>
              </ScrollViewer.Template>
            </ScrollViewer>

          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="WordWrap"
						         Value="True">
              <Setter TargetName="PART_ScrollViewer"
							        Property="HorizontalScrollBarVisibility"
							        Value="Disabled" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>